package com.wxg.my.d01;

public class DaemonPrinterV1 {

    private static InnerRun innerRun = new InnerRun();
    
    public static InnerRun forClass(Class<?> clazz) {
        innerRun.setClazz(clazz);
        return innerRun;
    }
    public static InnerRun interval(long interval) {
        innerRun.setInterval(interval);
        return innerRun;
    }

    private static class InnerRun implements Runnable {
        private Class<?> clazz;
        private long interval;
        @Override
        public void run() {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("Interrupted!");
                    break;
                }
                System.out.println();
                try {
                    Thread.sleep(interval);
                } catch (InterruptedException e) {
                    System.out.println("Interrupted When Sleep");
                    Thread.currentThread().interrupt();
                }
            }

        }

        public void setClazz(Class<?> clazz) {
            this.clazz = clazz;
        }

        public void setInterval(long interval) {
            this.interval = interval;
        }
    }
}
